package app.fugema.shop.main.home.adapter;

import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.MyLinearLayoutManager;
import com.base.common.view.adapter.ada.BaseRVAdapter;
import com.base.common.view.adapter.ada.GeneralRecyclerAdapter;

import com.base.common.view.adapter.connector.BaseItemMultiType;
import com.base.common.view.adapter.connector.BaseItemTypeInterface;
import com.base.common.view.adapter.connector.BaseViewHolder;

import app.fugema.shop.R;
import app.fugema.shop.databinding.HomeItemLinkImgListViewBinding;
import app.fugema.shop.main.home.model.HomeData;
import app.fugema.shop.main.home.model.ImgLinkData;

public class HomeImgLinkBaseItemMultiType extends BaseItemMultiType<ImgLinkData, HomeItemLinkImgListViewBinding>
{

    @Override
    public int getLayoutId()
    {
        return R.layout.home_item_link_img_list_view;
    }

    @Override
    public int getItemViewType() {
        return TYPE_HEAD_TWO;
    }

    @Override
    public boolean isFullSpanType() {
        return true;
    }

    @Override
    public void onCreateViewHolder(HomeItemLinkImgListViewBinding binding, BaseViewHolder viewHolder)
    {
        super.onCreateViewHolder(binding, viewHolder);

        binding.rvRecyclerView.setLayoutManager(new MyLinearLayoutManager(viewHolder.itemView.getContext()));
        GeneralRecyclerAdapter adapter = new GeneralRecyclerAdapter()
        {
            @Override
            public void initMultiItemType()
            {
                putMultiItemType( new HomeLink20MultiType() );
                putMultiItemType( new HomeLink21MultiType() );
                putMultiItemType( new HomeLink22MultiType() );
                putMultiItemType( new HomeLink23MultiType() );
                putMultiItemType( new HomeLink24MultiType() );
            }

            @Override
            public int getItemViewType(int position)
            {
                if(  getItemBean( position ) instanceof  HomeData.LModulesBean )
                {
                    HomeData.LModulesBean tempDate = (HomeData.LModulesBean)getItemBean( position );
                    if( tempDate.getType() == 20 )
                    {
                        return BaseItemTypeInterface.TYPE_CHILD_ONE;
                    }
                    else if( tempDate.getType() == 21 )
                    {
                        return BaseItemTypeInterface.TYPE_CHILD_TWO;
                    }
                    else if( tempDate.getType() == 22 )
                    {
                        return BaseItemTypeInterface.TYPE_CHILD_THREE;
                    }
                    else if( tempDate.getType() == 23 )
                    {
                        return BaseItemTypeInterface.TYPE_CHILD_FOUR;
                    }
                    else if( tempDate.getType() == 24 )
                    {
                        return BaseItemTypeInterface.TYPE_CHILD_FIVE;
                    }
                }
                return super.getItemViewType(position);
            }
        };
        binding.rvRecyclerView.setAdapter(adapter);
    }

    @Override
    public void onBindViewHolder(HomeItemLinkImgListViewBinding binding, int position, ImgLinkData bean)
    {
        super.onBindViewHolder(binding, position, bean);
        if (binding.rvRecyclerView.getAdapter() instanceof BaseRVAdapter)
        {
            BaseRVAdapter rvAdapter = (BaseRVAdapter) binding.rvRecyclerView.getAdapter();
            if (UIUtils.isNotEmpty(bean.getData()))
            {
                rvAdapter.setDataList(bean.getData());
            }
        }
    }

}
